﻿/*
 * @Author: z.p
 * @Project: Zdotp
 * @Date: 2024年12月31日 13:12:49 星期二
 * @Description: app基类
 */

using System.Net;
using System.Net.Sockets;
using Zdotp.Logs;

namespace Zdotp.Net.Kcp.App;

public abstract class ZyKcpApp
{
    protected UdpClient Udp;
    protected IPEndPoint RemotePoint;

    protected CancellationTokenSource Cts;

    protected readonly ZLogger KcpLogger = LogHelper.CreateLogger("ZyKcpApp");
    
    public Action<KcpSession> OnConnected;
    public Action<KcpSession> OnDisconnected;
    public Action<KcpSession, byte[]> OnReceive;

    protected virtual void SendUdpMessage(byte[] bytes, IPEndPoint remotePoint) => Udp?.Send(bytes, bytes.Length, remotePoint);

    public virtual void Start(string ip, int port)
    {
        Cts = new CancellationTokenSource();
    }
    public abstract void Close();
}